package com.zry.pda.adapter

import android.content.Context
import android.databinding.adapters.TextViewBindingAdapter.setText
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.zry.pda.R
import com.zry.pda.animation.MyBaseViewHolder
import com.zry.pda.been.*
import com.zry.pda.greendao.entity.OutTreasuryCode
import com.zry.pda.greendao.entity.PackingOperationInfo
import com.zry.pda.greendao.entity.PutStorageCode
import com.zry.pda.utils.DateTimeUtilsKt
import com.zry.pda.utils.StringListUtil

class HomePageAdapter(layoutResId: Int, data: MutableList<BasicBean>?) :
    BaseQuickAdapter<BasicBean, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: BasicBean?) {
        helper?.setText(R.id.itemHomePageTV, item?.BasicName)
            ?.setBackgroundRes(R.id.itemHomePageImg, item!!.BasicImg)
    }
}

class TraceCodeListAdapter(layoutResId: Int, data: MutableList<LongAndShortCode>) :
    BaseQuickAdapter<LongAndShortCode, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: LongAndShortCode?) {
        helper?.setText(R.id.traceCodeText, item?.longCode)?.addOnClickListener(R.id.traceCodeDeleteImg)
    }
}

class ComplementCodeAdapter(layoutResId: Int, data: MutableList<HomePageBean>?) :
    BaseQuickAdapter<HomePageBean, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: HomePageBean?) {
        helper?.setText(R.id.itemComplementCodeTV, item?.homePageName)
            ?.setBackgroundRes(R.id.itemComplementCodeImg, item!!.homePageImg)
    }
}


class PutStorageMethodAdapter(context: Context, data: MutableList<PutStorageMethod>) :
    BaseSpinnerAdapter<PutStorageMethod>(context, data) {
    override fun convert(convertView: TextView, item: PutStorageMethod?) {
        convertView.text = item?.putStorageName
    }
}

class ProductNameAdapter(context: Context, data: MutableList<ProductInfo>) :
    BaseSpinnerAdapter<ProductInfo>(context, data) {
    override fun convert(convertView: TextView, item: ProductInfo?) {
        convertView.text = item?.ProductName
    }
}

class ProductLineAdapter(context: Context, data: MutableList<ProductLine>) :
    BaseSpinnerAdapter<ProductLine>(context, data) {
    override fun convert(convertView: TextView, item: ProductLine?) {
        convertView.text = item?.ProductionLineName
    }
}

class BatchInfoAdapter(context: Context, data: MutableList<BatchInfo>) : BaseSpinnerAdapter<BatchInfo>(context, data) {
    override fun convert(convertView: TextView, item: BatchInfo?) {
        convertView.text = item?.BatchName
    }
}

class PackInfoAdapter(context: Context, data: MutableList<PacKBean>) : BaseSpinnerAdapter<PacKBean>(context, data) {
    override fun convert(convertView: TextView, item: PacKBean?) {
        convertView.text = item?.PackName
    }
}

class CodeListAdapter(layoutResId: Int, data: MutableList<CodeList>) :
    BaseQuickAdapter<CodeList, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: CodeList?) {
        helper?.setText(R.id.itemCodeListTV, item?.Code)
    }
}

class CodeListStringAdapter(layoutResId: Int, data: MutableList<String>) :
    BaseQuickAdapter<String, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: String?) {
        helper?.setText(R.id.itemCodeListTV, item)
    }
}


class OperationRecordAdapter01(layoutResId: Int, data: MutableList<FlowCode>?) :
    BaseQuickAdapter<FlowCode, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: FlowCode?) {
        helper?.setText(R.id.itemOperationTime, "打包时间：" + item?.CreateDate)
            ?.setText(R.id.itemProductName, item?.ProductName)
            ?.setText(R.id.itemDismantlingNumberTV, "打包数量：")
            ?.setText(R.id.itemDismantlingNumber, item?.Quantity)
            ?.setText(R.id.itemOperatorText, item?.CreateUserName)

        when (item?.FlowLevel) {
            "2" -> helper?.setText(R.id.itemBoxingLevel, "二级码打包")
            "3" -> helper?.setText(R.id.itemBoxingLevel, "三级码打包")
        }
    }
}

class StoreOrderListAdapter(layoutResId: Int, data: MutableList<StoreOrderBean>?) :
    BaseQuickAdapter<StoreOrderBean, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: StoreOrderBean?) {
        helper?.setText(R.id.itemOrderOperationTime, "入库单号：" + item?.StoreOrderCode)
            ?.setText(R.id.itemOrderProductName, item?.ProductName)
            ?.setText(R.id.itemCreationTime, item?.CreateDate)
    }
}

class OutStockListAdapter(layoutResId: Int, data: MutableList<OutStock>?) :
    BaseQuickAdapter<OutStock, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: OutStock?) {
        helper?.setText(R.id.itemOrderOperationTime, "出库单号：" + item?.OutStockCode)
            ?.setText(R.id.itemOrderProductNameTV, "接受经销商：")
            ?.setText(R.id.itemOrderProductName, item?.CustomerName)
            ?.setText(R.id.itemCreationTime, item?.CreateDate)
    }
}

class StoreDetailListAdapter(layoutResId: Int, data: MutableList<StoreDetail>?) :
    BaseQuickAdapter<StoreDetail, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: StoreDetail?) {
        helper?.setText(R.id.itemOperationTime, "入库单号：" + item?.StoreOrderCode)
            ?.setText(R.id.itemProductName, item?.ProductName)
            ?.setText(R.id.itemBoxingLevelTV, "入库数量：")
            ?.setText(R.id.itemDismantlingNumberTV, "入库时间：")
            ?.setText(R.id.itemDismantlingNumber, item?.StoreDate)
            ?.setText(R.id.itemOperatorText, item?.CreateUserName)

        if (item?.CodeS != "" && item?.CodeS != null) {
            val codeScan = StringListUtil().getList(item.CodeS).size.toString()
            helper?.setText(R.id.itemBoxingLevel, codeScan)
        } else {
            helper?.setText(R.id.itemBoxingLevel, "0")
            try {
                val codeS = (StringListUtil().getStringIntercept(
                    item!!.MaxCode,
                    8
                ).toInt() - StringListUtil().getStringIntercept(item.MinCode, 8).toInt()) + 1
                helper?.setText(R.id.itemBoxingLevel, codeS.toString())
            } catch (e: Exception) {
                e.printStackTrace()
            }
        }
    }
}

class OutDetailAdapter(layoutResId: Int, data: MutableList<OutDetailBean>?) :
    BaseQuickAdapter<OutDetailBean, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: OutDetailBean?) {
        helper?.setText(R.id.itemOperationTime, "出库单号：" + item?.OutStockCode)
            ?.setText(R.id.itemProductNameTV, "接收经销商:")
            ?.setText(R.id.itemProductName, item?.CustomerName)
            ?.setText(R.id.itemBoxingLevelTV, "出库数量：")
            ?.setText(R.id.itemBoxingLevel, item?.Quantity)
            ?.setText(R.id.itemDismantlingNumberTV, "出库时间：")
            ?.setText(R.id.itemDismantlingNumber, item?.OutStockDate)
            ?.setText(R.id.itemOperatorText, item?.CreateUserName)
    }
}

class FlowRecordAdapter(layoutResId: Int, data: MutableList<FlowRecord>?) :
    BaseQuickAdapter<FlowRecord, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: FlowRecord?) {
        when (item?.StateID) {
            "1" -> helper?.setText(R.id.itemOperationTime, "拆码时间：" + item?.CreateDate)
            "2" -> helper?.setText(R.id.itemOperationTime, "补码时间：" + item?.CreateDate)
        }
        helper?.setText(R.id.itemProductNameTV, "产品名称:")
            ?.setText(R.id.itemProductName, item?.ProductName)
            ?.setText(R.id.itemDismantlingNumberTV, "补码数量：")
            ?.setText(R.id.itemDismantlingNumber, item?.Quatity)
            ?.setText(R.id.itemOperatorText, item?.CreateUserName)
            ?.setText(R.id.itemBoxingLevelTV, "装箱级别：")

        when (item?.RecordType) {
            "1" -> helper?.setText(R.id.itemBoxingLevel, "单码装箱")
            "2" -> helper?.setText(R.id.itemBoxingLevel, "二级码装箱")
            "3" -> helper?.setText(R.id.itemBoxingLevel, "三级码装箱")
        }
    }
}

class PutStorageAdapter(layoutResId: Int, data: MutableList<PutStorageCode>?) :
    BaseQuickAdapter<PutStorageCode, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: PutStorageCode?) {
        helper?.setText(R.id.itemOperationTime, "入库单号：" + item?.orderCode)
            ?.setText(R.id.itemProductNameTV, "产品名称：")
            ?.setText(R.id.itemProductName, item?.productName)
            ?.setText(R.id.itemBoxingLevelTV, "入库方式：")
            ?.setText(R.id.itemDismantlingNumberTV, "录入时间：")
            ?.setText(R.id.itemDismantlingNumber, DateTimeUtilsKt().getUserDataTime(item!!.timeID))
            ?.setText(R.id.itemOperatorTextTV, "扫码数量：")

        if (item?.codeS != null && item.codeS != null) {
            helper?.setText(R.id.itemOperatorText, StringListUtil().getList(item.codeS).size.toString())
        } else {
            val codeNumber =
                StringListUtil().getStringIntercept(item!!.maxCode, 6).toInt() - StringListUtil().getStringIntercept(
                    item.minCode,
                    6
                ).toInt()
            helper?.setText(R.id.itemOperatorText, (codeNumber + 1).toString())
        }
        when (item.putStoreType) {
            "1" -> helper?.setText(R.id.itemBoxingLevel, "单品入库")
            "2" -> helper?.setText(R.id.itemBoxingLevel, "二级码入库")
            "3" -> helper?.setText(R.id.itemBoxingLevel, "三级码入库")
        }
    }
}

class OutTreasuryAdapter(layoutResId: Int, data: MutableList<OutTreasuryCode>?) :
    BaseQuickAdapter<OutTreasuryCode, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: OutTreasuryCode?) {
        helper?.setText(R.id.itemOperationTime, "出库单号：" + item?.outStockCode)
            ?.setText(R.id.itemProductNameTV, "产品名称:")
            ?.setText(R.id.itemProductName, item?.productName)
            ?.setText(R.id.itemBoxingLevelTV, "接收经销商：")
            ?.setText(R.id.itemBoxingLevel, item?.customerName)
            ?.setText(R.id.itemDismantlingNumberTV, "出库时间：")
            ?.setText(R.id.itemDismantlingNumber, DateTimeUtilsKt().getUserDataTime(item!!.timeID))
            ?.setText(R.id.itemOperatorTextTV, "扫码数量：")

        if (item?.codes != null && item.codes != null) {
            helper?.setText(R.id.itemOperatorText, StringListUtil().getList(item.codes).size.toString())
        } else {
            val codeNumber =
                StringListUtil().getStringIntercept(item!!.maxCode, 6).toInt() - StringListUtil().getStringIntercept(
                    item.minCode,
                    6
                ).toInt()
            helper?.setText(R.id.itemOperatorText, (codeNumber + 1).toString())
        }
    }
}

class PackingOperationAdapter(layoutResId: Int, data: MutableList<PackingOperationInfo>?) :
    BaseQuickAdapter<PackingOperationInfo, MyBaseViewHolder>(layoutResId, data) {
    override fun convert(helper: MyBaseViewHolder?, item: PackingOperationInfo?) {
        helper?.setText(R.id.itemOperationTime, "操作时间：" + DateTimeUtilsKt().getUserDataTime(item!!.timeID))
            ?.setText(R.id.itemProductNameTV, "产品名称:")
            ?.setText(R.id.itemProductName, item.productName)
            ?.setText(R.id.itemBoxingLevelTV, "装箱单位：")
            ?.setText(R.id.itemBoxingLevel, item.packUnitName)
            ?.setText(R.id.itemDismantlingNumberTV, "装箱比例：")
            ?.setText(R.id.itemDismantlingNumber, item.packProportion + "：1")
            ?.setText(R.id.itemOperatorTextTV, "打包数量：")

        if (item?.submitCode != null && item.submitCode != null) {
            helper?.setText(R.id.itemOperatorText, StringListUtil().getList(item.submitCode).size.toString())
        } else {
            val codeNumber = StringListUtil().getStringIntercept(
                item!!.submitMaxCode,
                6
            ).toInt() - StringListUtil().getStringIntercept(item.submitMinCode, 6).toInt()
            helper?.setText(R.id.itemOperatorText, (codeNumber + 1).toString())
        }
    }
}


